-- drop foreign key 1
if exists (select * from sys.foreign_keys where name = 'fk_Nhanvien_phongban')
begin
	alter table NHANVIEN drop constraint fk_Nhanvien_phongban
end
go
--foreign key 1

alter table NHANVIEN 
add constraint fk_Nhanvien_phongban 
foreign key (PHG) 
references PHONGBAN(MAPHG)
--drop foreign key 2
if exists (select * from sys.foreign_keys where name='fk_Nhanvien_Phancong')
begin
	alter table PHANCONG drop constraint fk_Nhanvien_Phancong
end
go

alter table PHANCONG
add constraint fk_Nhanvien_Phancong
foreign key (MA_NVIEN)
references NHANVIEN(MANV)

--drop foreign key 3
if exists (select * from sys.foreign_keys where name = 'fk_phancong_dean')
begin
	alter table PHANCONG drop constraint fk_Phancong_dean
end
Go

alter table PHANCONG
add constraint fk_Phancong_dean
foreign key (SODA)
references dean(MADA)
--drop foreign key 4

if exists (select * from sys.foreign_keys where name ='fk_nhanvien_thannhan')
begin
	alter table THANNHAN drop constraint fk_nhanvien_thannhan
end
go

alter table THANNHAN
add constraint fk_nhanvien_thannhan
foreign key (MA_NVIEN)
references NHANVIEN(MANV)
--drop foreign key 5
if exists (select * from sys.foreign_keys where name ='fk_phongban_DD_PHG')
begin
	alter table PHONGBAN drop constraint fk_phongban_DD_PHG
end
go
alter table DIADIEM_PHG
add constraint fk_phongban_DD_PHG
foreign key (MAPHG)
references PHONGBAN(MAPHG)
--drop foreign key 6
if exists (select *from sys.foreign_keys where name ='fk_Nhanvien_Phongban')
begin
	alter table PHONGBAN drop constraint fk_Nhanvien_Phongban
end
go
alter table PHONGBAN
add constraint fk_Phongban_Nhanvien
foreign key (TRPHG)
references NHANVIEN(MANV)